package com.feihong.txgw.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.feihong.txgw.R;
import com.feihong.txgw.adapter.Holder.BaseViewHolder;
import com.feihong.txgw.adapter.Holder.ProductOrderDetailGoodsViewHolder;
import com.feihong.txgw.adapter.Holder.ProductOrderDetailHeadViewHolder;
import com.feihong.txgw.ui.fragment.order.OrderListFragment;
import com.feihong.txgw.json.user.ProductOrderDetailEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * @name txgw_app
 * @class name：com.feihong.txgw.adapter
 * @class describe:
 * @author wangziheng
 * @time 2017/8/16 12:34
 * @change
 * @chang time
 * @class describe
 */
public class ProductOrderDetailAdapter extends RecyclerView.Adapter<BaseViewHolder> {
    private Context mContext;
    private List<ProductOrderDetailEntity> mOrderGoods;
    private static final int PRODUCT_DETAIL_HEAD = 1;
    private static final int PRODUCT_DETAIL_LIST = 2;
    private OrderListFragment.OrderRefreshCallBack mRefreshCallBack;
    public ProductOrderDetailAdapter(Context context,OrderListFragment.OrderRefreshCallBack refreshCallBack){
        mContext = context;
        mOrderGoods = new ArrayList<>();
        mRefreshCallBack = refreshCallBack;
    }
    public void setGoods(List<ProductOrderDetailEntity> goods ){
        mOrderGoods = goods;
        notifyDataSetChanged();
    }
    public void setClear(){
        mOrderGoods.clear();
        notifyDataSetChanged();
    }
    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if(viewType == PRODUCT_DETAIL_HEAD){
            return new ProductOrderDetailHeadViewHolder(LayoutInflater.from(mContext).inflate(R.layout.product_order_detail_head_layout,parent,false));
        }else {
            return new ProductOrderDetailGoodsViewHolder(mRefreshCallBack,LayoutInflater.from(mContext).inflate(R.layout.product_order_detail_goods_detail_layout,parent,false),mContext);
        }
    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, int position) {
        if(PRODUCT_DETAIL_HEAD == getItemViewType(position)){
            ProductOrderDetailHeadViewHolder mHolder = (ProductOrderDetailHeadViewHolder) holder;
            mHolder.initData(mOrderGoods);
        }else {
            ProductOrderDetailGoodsViewHolder mHolder = (ProductOrderDetailGoodsViewHolder) holder;
            mHolder.initData(mOrderGoods);
        }
    }

    @Override
    public int getItemCount() {
        return 2;
    }

    @Override
    public int getItemViewType(int position) {
        if(position == 0) {
            return PRODUCT_DETAIL_HEAD;
        } else {
            return PRODUCT_DETAIL_LIST;
        }
    }
}
